// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   Right.java

package include.tree_index;

import include.nseer_db.nseer_db;
import java.sql.ResultSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// Referenced classes of package include.tree_index:
//			Nseer

public class Right
{

	private String database;

	public Right(String database)
	{
		this.database = database;
	}

	public boolean hasRight(String unit_db_name, String user, String right)
	{
		nseer_db db = null;
		boolean flag = false;
		Nseer n = new Nseer();
		try
		{
			String table1 = (new StringBuilder(String.valueOf(database))).append("_view").toString();
			String table2 = (new StringBuilder(String.valueOf(database))).append("_tree").toString();
			db = new nseer_db(unit_db_name);
			right = right.substring(1);
			right = right.substring(right.indexOf("/") + 1);
			String filepath = right.substring(0, right.lastIndexOf("/") + 1);
			String filetemp = right.substring(right.lastIndexOf("/") + 1);
			String filename = "";
			if (filetemp.indexOf("_") != -1)
				filename = filetemp.substring(0, filetemp.indexOf("_"));
			else
				filename = filetemp;
			for (ResultSet rs = db.executeQuery((new StringBuilder("select hreflink from ")).append(table1).append(" r where r.human_ID='").append(user).append("' and r.file_path='").append(filepath).append("'").toString()); rs.next();)
			{
				String aa = (new StringBuilder(String.valueOf(filename))).append("[^a-zA-Z].*").toString();
				Pattern b = Pattern.compile(aa);
				Matcher m1 = b.matcher(rs.getString("hreflink"));
				if (m1.find())
				{
					flag = true;
					break;
				}
			}

			db.close();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			db.close();
			return flag;
		}
		return flag;
	}
}
